var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (d, b) {
            d.__proto__ = b;
          }) ||
        function (d, b) {
          for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
        };
      return extendStatics(d, b);
    };
    return function (d, b) {
      if (typeof b !== 'function' && b !== null)
        throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
      extendStatics(d, b);
      function __() {
        this.constructor = d;
      }
      d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
    };
  })();
var VDom = /** @class */ (function () {
  function VDom() {}
  VDom.prototype.createElement = function (el) {
    return document.createElement(el);
  };
  VDom.prototype.setElementText = function (el, text) {
    el.textContent = text;
  };
  VDom.prototype.render = function (vnode) {
    var _this = this;
    var root = this.createElement(vnode.tag);
    if (vnode.children && Array.isArray(vnode.children)) {
      vnode.children.forEach(function (child) {
        root.appendChild(_this.render(child));
      });
    } else {
      this.setElementText(root, vnode.text || '');
    }
    return root;
  };
  return VDom;
})();
var Vue = /** @class */ (function (_super) {
  __extends(Vue, _super);
  function Vue(options) {
    var _this = _super.call(this) || this;
    _this.options = options;
    _this.init();
    return _this;
  }
  Vue.prototype.init = function () {
    var _a;
    var data = {
      tag: 'div',
      children: [
        {
          tag: 'p',
          text: 'hello vue',
        },
        {
          tag: 'p',
          text: 'hello vue2',
        },
        {
          tag: 'p',
          text: 'hello vue3',
        },
      ],
    };
    var app = this.render(data);
    typeof this.options.el === 'string'
      ? (_a = document.querySelector(this.options.el)) === null || _a === void 0
        ? void 0
        : _a.appendChild(app)
      : this.options.el.appendChild(app);
  };
  return Vue;
})(VDom);
new Vue({
  el: '#app',
});
